package com.kuaiditu.assistant.api.kdy_api.base;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

/**
 * Created by Eenie on 2017/9/15.
 * Email: eeniework@gmail.com
 * Des:
 */

public class BaseSTResponse {


    /**
     * code : 0
     * msg : 成功
     * data : {"user_id":"1142160","session_id":"40561f879e54622df69acb78c9aabff8","area":"上海市-上海市-黄浦区","brand":"sto","index_shop_name":"上海徐汇东部公司","realname":"Eenie","codeId":"","idImg":"","realnameAuthStatus":0,"zb_status":"1","index_shop_id":"67337"}
     */

    private int code;
    private String msg;
    private String data;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {

        if (getDataEnJson().containsKey("code")) {
            return getDataEnJson().getString("desc");
        }

        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }


    public String getData() {
        return data;
    }

    public void setData(String data) {
        this.data = data;
    }


    public boolean isSuccess() {
        if (getDataEnJson().containsKey("code")) {
            return code == 0 && getDataEnJson().getInteger("code") == 0;
        }
        return code == 0;
    }


    public JSONObject getDataEnJson() {
        return JSON.parseObject(this.data);
    }


    public Object getDataEn(Class clz) {
        return JSON.parseObject(this.data, clz);
    }

}
